#ifndef COOKIEJAR_H
#define COOKIEJAR_H

#include <QPair>
#include <QMap>
#include <QString>
#include <QVariant>
#include <QList>
#include <QNetworkCookie>
#include <QDir>

class QNetworkAccessManager;

// For SocialWhale API
class OAuthTokenPair : public QPair< QString, QString > {
    public:
        OAuthTokenPair( QString tok = "", QString sec = "" ) : QPair< QString, QString >( tok, sec ) {
        }
        QString token() {
            return this->first;
        }
        QString secret() {
            return this->second;
        }
};

// A class for reading and storing cookies
class CookieJar {
    Q_GADGET

    public:
        CookieJar();
        QString activeAccount(); // get active account based on cookies
        OAuthTokenPair activeTokenPair(); // get oAuth token of active account
        QMap< QString, OAuthTokenPair > allAccounts(); // return all available accounts from cookies
        void fromNetworkManager( QNetworkAccessManager * manager ); // get cookies from browser
        static QList< QNetworkCookie > loginCookies(); // return all login cookies (static for global use)
        void setStoreDirectory( QDir dir ); // set directory to store cookie file

    public slots:
        void read();
        void clear();
        void store();
        void clearStorage();
        void accountsFromCookies(); // build accounts based on cookies read

    private:
        QMap< QString, OAuthTokenPair > sAccounts;
        static QList< QNetworkCookie > sLoginCookies; // keep this static for global use of loginCookies()
        QDir mStoreDirectory;
};

QDataStream& operator>>( QDataStream& s, QNetworkCookie & l );
QDataStream& operator<<(QDataStream& s, const QNetworkCookie& l);

#endif
